package fun.wxy.camera.util;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * 掌纹设备图片帧处理工具类
 */
public class PalmDeviceFrameUtil {

    private static final LinkedBlockingQueue<byte[]> complexFrameQueue = new LinkedBlockingQueue<>(1);

    /**
     * 添加图片帧
     */
    public static void addImageFrame(byte[] imgFrame) {
        synchronized (PalmDeviceFrameUtil.class) {
            if (imgFrame != null) {
                try {
                    complexFrameQueue.offer(imgFrame);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 消费图片帧
     */
    public static byte[] takeComplexFrame() throws InterruptedException {
        return complexFrameQueue.take();
    }

    /**
     * 判断图片帧是否为空
     */
    public static boolean isEmpty() {
        return complexFrameQueue.isEmpty();
    }

    /**
     * 清空图片帧
     */
    public static void resetQueue() {
        complexFrameQueue.clear();
    }

}
